package com.site.controller;

import com.site.common.R;
import com.site.vo.TestFormVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 测试表单验证，分组验证
 */
@RestController
@RequestMapping("/form")
public class FormValidationController extends BaseController {

    /**
     * 表单验证
     * @param formVo
     * @return
     */
    @PostMapping("/test")
    public R<TestFormVo> test(@RequestBody @Valid TestFormVo formVo){
        return R.ok(formVo);
    }

    /**
     * 表单验证 (注意：@Validated 无分组时与 @Valid效果一样)
     * @param formVo
     * @return
     */
    @PostMapping("/create")
    public R<TestFormVo> testCreate(@RequestBody @Validated(TestFormVo.Create.class) TestFormVo formVo){
        return R.ok(formVo);
    }

    /**
     * 表单验证
     * @param formVo
     * @return
     */
    @PostMapping("/update")
    public R<TestFormVo> testUpdate(@RequestBody @Validated(value = TestFormVo.Update.class) TestFormVo formVo){
        return R.ok(formVo);
    }
}
